<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\service\NodeService;
use library\Controller;
use library\tools\Data;
use think\Console;
use think\Db;
use think\Request;
use think\exception\HttpResponseException;

/**
 * 内容管理
 * Class Index
 * @package app\admin\controller
 */
class News extends Controller
{
    /**
     * 绑定数据表
     * @var string
     */
    protected $table = 'WebNews';
   
   

    /**
    * 内容管理
    * @auth true
    * @menu true
    */
    public function index(){

        $this->title="内容管理";
        $query = $this->_query($this->table)->equal('status,tid')->like('title');
        $query->order('sort desc,id desc')->page();
    }
    /**
     * 数据列表处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function _index_page_filter(&$data)
    {
        $this->clist = Db::name('WebNewsType')->where(['status' => '1'])->select();
        foreach ($data as &$vo) {
            list($vo['cate']) = [[]];
            foreach ($this->clist as $cate) if ($cate['id'] === $vo['tid']) $vo['cate'] = $cate;
        }
    }

    /**
    * 内容添加
    * @auth true
    */
    public function newsAdd(){

        $this->title="内容添加";
        $this->_form($this->table, 'news_add');
        
    }

    protected function _form_filter(&$data)
    {

      $this->cates = Db::name('WebNewsType')->where([ 'status' => '1'])->order('sort desc,id desc')->select();
        

    }

     /**
     * 表单结果处理
     * @param boolean $result
     */
    protected function _form_result($result)
    {
        if ($result && $this->request->isPost()) {
            $this->success('内容编辑成功！', 'javascript:history.back()');
        }
    }

    /**
    * 内容编辑
    * @auth true
    */
    public function edit()
    {
        $this->title = '编辑内容分类';
        $this->_form($this->table, 'news_add');
    }

    /**
    * 内容禁用
    * @auth true
     */
     public function forbid()
    {
        $this->_save($this->table, ['status' => '0']);
    }

    /**
     * 内容启用
    * @auth true
     */
    public function resume()
    {
        $this->_save($this->table, ['status' => '1']);
    }


 


}
